package reivew;

import java.util.Scanner;

/**
 * 程序的思维过程
 * 多想-多做。。。多模仿
 */
public class ChihuoLianMeng {
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        String foods[]={"爆炒龙肝","清炖凤髓","西红柿鸡蛋盖浇饭"};
        double price[]={99,54,13};
        int[]  prize={0,0,0};
        int choice=0;//选择
        final int max=6;
        String []names=new String[max];
        String []dishmsg=new String[max];
        String []deliveryAddress=new String[max];
        double []moneys=new double[max];
        int []states=new int[max];
        int []times=new int[max];
        int index=0;//记录当前有几份订单；记录下一个可用的餐袋
        while (true){
            System.out.println("1:我要订餐" +
                    "2：查看餐袋" +
                    "3：签收订单" +
                    "4:删除订单" +
                    "5:我要点赞" +
                    "6:退出系统");
            System.out.print("请选择:");
            choice=in.nextInt();
            if(choice==1){
                System.out.print("你的名字：");
                String customname=in.next();
                //显示餐品信息
                System.out.println("序号   菜名   价格   点赞数");
                for(int i=0;i<foods.length;i++){
                    System.out.println((i+1)+foods[i]+" "+price[i]+" "+prize[i]);
                }
                int select=0;// 1-3
                while (true){
                    select=in.nextInt();
                    if(select>=1&&select<=3)
                        break;//对了，退出！！！
                    System.out.println("输入错误，重来");
                }
                System.out.print("几份：");
                int fenshu=0;
                while (true){
                    fenshu=in.nextInt();
                    if (fenshu >=1) {
                        break;
                    }
                    System.out.println("输入错误，重来");
                }
                System.out.print("送餐时间:");//10点-23点
                int time=0;
                while (true){
                    time=in.nextInt();
                    if(time>=10&&time<=23)
                        break;
                    System.out.println("时间输入错误，重来");
                }
                System.out.print("送餐地址：");
                String address=in.next();
                int peisong=fenshu*price[select-1]>=50?0:5;
                double totalmoney=fenshu*price[select-1]+peisong;//总费用
                //往数组中加
                names[index]=customname;
                dishmsg[index]=foods[select-1]+" "+fenshu+" 份";
                deliveryAddress[index]=address;
                times[index]=time;
                moneys[index]=totalmoney;
                states[index]=0;//!可以不用
                System.out.println("您订购的是"+foods[select-1]+" "+fenshu+" 份"+"，配送费 "+peisong+"元"+" 总计 "+totalmoney+",送餐时间是 "+time);
                //序号+1
                index++;
                //                int i=0;
                //                for(;i<names.length;i++){
                //                    if(names[i]==null)
                //                     // index=i;   break;
                //                }
                //                names[i]=in.next();
            }
            else if(choice==2){
                System.out.println("查看餐袋");
                System.out.println("序号 订餐人 餐品信息  送餐时间  地址   总金额  订单完成");
                for(int i=0;i<index;i++){
                    System.out.print(i+1);
                    System.out.print("  "+names[i]);
                    System.out.print("  "+times[i]);
                    System.out.print("  "+deliveryAddress[i]);
                    System.out.print("  "+moneys[i]);
                    System.out.print("  "+(states[i]==1?"已完成":"已预定"));
                    System.out.println();//换行
                }
            }else  if(choice==3){
                System.out.println("订单签收");
                System.out.print("签收的订单序号：");
                int choose=0;//从1开始  1 到index
                //一个订单没有，while就死了
                if((choose=in.nextInt())>index||choose<1){
                    System.out.println("重来，输入错误");
                }else{
                    states[choose-1]=1;
                }
                //choose <index

            }else if(choice==4){
                System.out.println("删除订单");
                int choose=0;
                while(true){
                    choose= in.nextInt();
                    if(choose>=1 &&choose<=index)
                        break;
                    System.out.println("输入错误");
                }
                if(states[choose-1]!=1){
                    System.out.println("订单没有完成，不能删除！");
                }else{
                    //删除这个位置 choose-1
                    choose--;
                    //先移动
                    for(int i=choose;i<names.length-1;i++){
                        names[i]=names[i+1];
                        deliveryAddress[i]=deliveryAddress[i+1];
                        times[i]=times[i+1];
                        moneys[i]=moneys[i+1];
                        dishmsg[i]=dishmsg[i+1];
                        states[i]=states[i+1];
                    }
                    names[names.length-1]=null;//防止最后一个还在
                    deliveryAddress[names.length-1]=null;//防止最后一个还在
                    times[names.length-1]=0;//防止最后一个还在
                    moneys[names.length-1]=0;//防止最后一个还在
                    states[names.length-1]=0;
                    dishmsg[names.length-1]=null;
                    index--;//!!!!
                }
            } else if(choice==6){
                return;
            }

            System.out.println("输入0返回");
            String r=in.next();
        }
    }
}
